package leetcode.part1;

import org.junit.Test;

public class S12 {
    public String intToRoman(int num) {
        int[] vals={1000,900,500,400,100,90,50,40,10,9,5,4,1};
        int index=0;
        StringBuilder builder=new StringBuilder();
        while (num>0){
            if (num-vals[index]<0){
                index++;
            }else {
                num=num-vals[index];
                builder.append(translate(vals[index]));
            }
        }
        return builder.toString();
    }
    private String translate(int num){
        String result;
        switch (num){
            case 1000:
                result="M";
                break;
            case 500:
                result="D";
                break;
            case 100:
                result="C";
                break;
            case 50:
                result="L";
                break;
            case 10:
                result="X";
                break;
            case 5:
                result="V";
                break;
            case 1:
                result="I";
                break;
            case 4:
                result="IV";
                break;
            case 9:
                result="IX";
                break;
            case 40:
                result="XL";
                break;
            case 90:
                result="XC";
                break;
            case 400:
                result="CD";
                break;
            case 900:
                result="CM";
                break;
            default:
                result="";
        }
        return result;
    }
    @Test
    public void test(){
        int a=3;
        System.out.println(intToRoman(a));
    }
}
